< previous page page_486 next page >

Page 486
e10a6a0a59f035e870d90cca05b85fce.gif
Dim Y As Single
Dim dy As Single

    ' Deal only with integers.
    x1 = CInt(x1)
    y1 = CInt(y1)
    x2 = CInt(x2)
    y2 = CInt(y2)

    ' Make x1 < x2.
    If x2 < x1 Then
        tmp = x1
        x1 = x2
        x2 = tmp
        tmp = y1
        y1 = y2
        y2 = tmp
    End If

    ' Draw the line.
    pic.Line (x1, y1)-(x2, y2)

    ' Deal with vertical lines separately.
    If x1 = x2 Then
        If y1 < y2 Then
            lo(x1) = y1
            hi(x1) = y2
        Else
            lo(x1) = y2
            hi(x1) = y1
        End If
        Exit Sub
    End If

    ' Deal with non-vertical lines.
    dy = (y2 - y1) / CInt(x2 - x1)
    Y = y1
    For ix = x1 To x2
        iy = CInt(Y)

        lo(ix) = iy
        hi(ix) = iy

        Y = Y + dy
    Next ix
End Sub

' Draw a line between the points using and
' updating the hi and lo arrays.
Private Sub DrawLine(ByVal pic As PictureBox, _
    ByVal x1 As Single, ByVal y1 As Single, _

 
< previous page page_486 next page >